package com.estate.console.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.estate.bean.Console;
import com.estate.bean.Quarters;
import com.estate.console.feign.CommunityFeign;
import com.estate.console.feign.ComplaintsFeign;
import com.estate.console.feign.OwnerFeign;
import com.estate.console.feign.ParkingFeign;
import com.estate.console.service.ConsoleService;
import com.estate.util.JsonResult;
import com.estate.util.ResultTool;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class ConsoleServiceImpl implements ConsoleService {

    @Resource
    private CommunityFeign communityFeign;

    @Resource
    private OwnerFeign ownerFeign;

    @Resource
    private ComplaintsFeign complaintsFeign;

    @Resource
    private ParkingFeign parkingFeign;

    @Override
    public JsonResult find() {
        List<Console> consoleList = new ArrayList<>();
        List<Quarters> quartersList = communityFeign.findAll();
        quartersList.forEach(e -> {
            Console console = new Console();
            console.setCommunityId(e.getId());
            console.setTotalBuildings(e.getTotalBuildings());
            console.setTotalHouses(e.getTotalHouseholds());
            console.setTotalOwners(ownerFeign.findByCommunityId(e.getId()));
            console.setTotalComplaints(complaintsFeign.findByCommunityId(e.getId()));
            console.setTotalParking(parkingFeign.findByCommunityId(e.getId()));
            consoleList.add(console);
        });
        log.info("consoleList:{}", consoleList);
        return ResultTool.success(consoleList);
    }
}
